package leetcode.link;

public class Test206 {

    public static void main(String[] args) {
//        ListNode node = new ListNode(6);
//        ListNode n2 = new ListNode(5,node);
        ListNode n3 = new ListNode(5,null);
        ListNode n4 = new ListNode(4,n3);
        ListNode n5 = new ListNode(3,n4);
        ListNode n6 = new ListNode(2,n5);
        ListNode n7 = new ListNode(1,n6);
        ListNode node1 = reverseList(n7);
        while (node1.next != null){
            System.out.println(node1.val);
            node1 = node1.next;
        }
        System.out.println(node1.val);
    }

//    输入：head = [1,2,3,4,5]
//    输出：[5,4,3,2,1]
    public static ListNode reverseList(ListNode head) {

        ListNode current = head;
        ListNode prev = null;
        ListNode next;
        while (current!=null){
            System.out.println(current.val);
            next = current.next;
            current.next = prev;
            prev = current;
            current = next;
        }
        return prev;
    }
}
